import React, {useRef} from 'react';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import ProTable from '@ant-design/pro-table';
import { getDistributeLeaveList} from '../service';
import { BPMStatusEnum } from '@/utils/constant'
import moment from 'moment';

const TableList = () => {
  const actionRef = useRef();

  const columns = [
    {
      title: '工号',
      hideInSearch: true,
      dataIndex: 'code',
    },
    {
      title: '姓名',
      dataIndex: 'name',
    },
    {
      title: '公司',
      dataIndex: 'orgname',
    },
    {
      title: '部门',
      dataIndex: 'unitname',
    },
    {
      title: '调休开始日期',
      dataIndex: 'leaveBeginTime',
      hideInSearch: true,
      render: (text) => {
        return moment(text).format('YYYY-MM-DD HH:mm');
      },
    },
    {
      title: '调休结束日期',
      dataIndex: 'leaveEndTime',
      hideInSearch: true,
      render: (text) => {
        return moment(text).format('YYYY-MM-DD HH:mm');
      },
    },
    {
      title: '调休时长',
      dataIndex: 'leaveTime',
      hideInSearch: true,
      render: (text) => {
        return text !== '-' ? text + `小时` : '';
      }
    },
    {
      title: '审批状态',
      dataIndex: 'status',
      hideInSearch: true,
      valueEnum: BPMStatusEnum
    },
    {
      title: '操作',
      dataIndex: 'option',
      valueType: 'option',
      align:'center',
      render: (item, record) => (
        <>
          {(record.status !== 1 && record.checkUrl) && <><a onClick={() => window.open(record.checkUrl)}>审批详情</a></>}
        </>
      ),
    }
  ];

  return (
    <PageHeaderWrapper>
      <ProTable
        actionRef={actionRef}
        rowKey="id"
        request={(params) => getDistributeLeaveList(params)}
        columns={columns}
      />
    </PageHeaderWrapper>
  )
};

export default (TableList);
